Skip to main content

CountrySelector API

CountrySelector is a button component for selecting a country.

Usage Example

Import component

import { CountrySelector } from 'react-international-phone';

Use by providing the selectedCountry and onSelect callback.

<CountrySelector
selectedCountry="ua"
onSelect={({ iso2 }) => setCountry(iso2)}
/>

Output:

Properties

PropTypeDescriptionDefault value
selectedCountryCountryIso2Selected country (iso2)undefined
disabledbooleanIs CountrySelector disabledundefined
hideDropdownbooleanHide dropdown icon and make CountrySelector not clickableundefined
renderButtonWrapper(props: { children: React.ReactNode; rootProps: React.ButtonHTMLAttributes<HTMLButtonElement>) => React.ReactNodeRender function for custom button wrapper. children and rootProps should be passed to button props. rootProps contains a click handler and properties that are required for accessibility. rootProps should be spread like <button {...rootProps}>undefined

Events

PropTypeDescription
onSelect(country: ParsedCountry) => voidCallback that calls on country select

Style properties (CountrySelectorStyleProps type)

PropTypeDescription
styleCSSPropertiesCustom styles for CountrySelector container
classNamestringCustom className for CountrySelector container
buttonStyleCSSPropertiesCustom styles for CountrySelector button
buttonClassNamestringCustom className for CountrySelector button
buttonContentWrapperStyleCSSPropertiesCustom styles for CountrySelector button content wrapper
buttonContentWrapperClassNamestringCustom className for CountrySelector button content wrapper
flagStyledropdownStylePropsCustom styles for CountrySelector flag
flagClassNamestringCustom className for CountrySelector flag
dropdownArrowStyledropdownStylePropsCustom styles for CountrySelector dropdown arrow
dropdownArrowClassNamestringCustom className for CountrySelector dropdown arrow
dropdownStylePropsCountrySelectorDropdownStylePropsStyle properties for CountrySelector dropdown

CSS variables

VariableDefault value
--react-international-phone-country-selector-background-color--react-international-phone-background-color
--react-international-phone-country-selector-background-color-hoverwhitesmoke
--react-international-phone-disabled-country-selector-background-color--react-international-phone-disabled-background-color
--react-international-phone-country-selector-border-color13px
--react-international-phone-country-selector-arrow-size4px
--react-international-phone-country-selector-arrow-color#777
--react-international-phone-disabled-country-selector-arrow-color#999